package cn.gok.homework;

import java.util.Scanner;

class Person {
    private String name;
    private String sex;
    private int age;
    private boolean isMarried;

    private boolean isEnoughAge() {
        boolean flag = false;
        if (!(this.isMarried)) {
            if ((this.sex.equals("female") && this.age >= 19) || (this.sex.equals("male") && this.age >= 20)) {
                flag = true;
            } else {
                System.out.println(this.name + "年龄不足或性别有误！");
            }
        } else {
            System.out.println(this.name + "已婚！");
        }
        return flag;
    }

    public static boolean marrayWith(Person p1, Person p2) {
        boolean flag = false;
        if (!(p1.getSex().equals(p2.getSex()))) {
            if (p1.isEnoughAge() && p2.isEnoughAge()) {
                System.out.println(p1.name + "与" + p2.name + "结婚了");
                flag = true;
                //更新状态
                p1.setMarried(true);
                p2.setMarried(true);
            }
        } else {
            System.out.println("只支持异性");
        }
        return flag;
    }

    public void study(String school) {
    }

    public Person(String name, String sex, int age, boolean isMarried) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.isMarried = isMarried;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isMarried() {
        return isMarried;
    }

    public void setMarried(boolean married) {
        isMarried = married;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", isMarried=" + isMarried +
                '}';
    }
}


public class HomeWork3 {
    public static void main(String[] args) {
        Person p1 = new Person("xx", "male", 20, false);
        Person p2 = new Person("zzz", "male", 20, false);
        Person p3 = new Person("yyy", "female", 18, false);
        Person p4 = new Person("kkk", "female", 19, false);
        Person.marrayWith(p1, p2);
        Person.marrayWith(p1, p3);
        Person.marrayWith(p1, p4);
        Person person = new Person("A", "male", 21, false) {
            @Override
            public void study(String school) {
                System.out.println("输入学习年数：");
                int year=new Scanner(System.in).nextInt();
                System.out.println("在"+school+"学校学习了"+year+"年");
            }
        };
        person.study("qzd");
    }
}
